package com.woniu.project.service.impl;

import com.woniu.project.core.domain.Image;
import com.woniu.project.core.exception.ProjectProductException;
import com.woniu.project.service.IImageService;
import com.woniu.project.service.UploadService;
import com.woniu.project.web.common.UploadImg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
@Service
public class UploadServiceImpl implements UploadService {
    @Autowired
    IImageService imageService;
    @Override
    public String iconUpload(MultipartFile file) {
        Image image = new Image();
        try {
            String addr = UploadImg.upLoad(file);
            image.setImageAddr(addr);
            imageService.save(image);
            return addr;
        } catch (Exception e) {
            e.printStackTrace();
            throw new ProjectProductException(500,"文件上传异常");
        }
    }
}
